import React from 'react';
import { connect } from 'dva';
import VortexSelect,{VortexOption, VortexOptGroup, VortexCascader} from '../components/VortexSelect';

function Demo(props){
    const {dispatch,emValue,emOptions} = props;
    const selectProps = {
        style: { width: 150 },
        placeholder:'选一个',
        value:emValue,
        vobj:{
            name:'tttttttttt',
            id:'244223'
        },
        onChange(value){
          dispatch({type:'example/fetch',payload:{
            emValue:value
          }})
        }
      }
    return (
        <div>
            <VESelect {...{selectProps,options:emOptions}}/>
        </div>
    )
}

function VESelect(props){
    let {selectProps,options} = props;
    if(options.map(item=>item.id).indexOf(selectProps.value)==-1){
        options = [selectProps.vobj, ...options];
    }
    return (
        <VortexSelect {...selectProps} >
        {
            options.map((item)=>{
            return (<VortexOption value={item.id}  key={item.id}>{item.name}</VortexOption>)
            })
        }
        </VortexSelect>
    )
}
  export default connect(({example})=>example)(Demo);